<?php

namespace app\common\validate;

use think\Validate;

class ConfigValidate extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...].
     *
     * @var array
     */
    protected $rule = [
        'id|编号' => 'require|number|gt:0',
        'keyword|搜索内容' => 'min:2',
        'category|配置分类' => 'require|min:2',
        'name|配置名称' => 'require|chsAlpha|min:2',
        'tag|配置标识' => 'require|min:2|unique:config',
        'value|配置内容' => 'min:2',
        'value_type|配置内容类型' => 'require|in:1,2,3,4',
        'describe|配置描述' => 'require',
        'config_list|配置列表' => 'require',
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'.
     *
     * @var array
     */
    protected $message = [];
    protected $scene = [
        'getListPage' => ['page', 'limit', 'keyword'],
        'saveAdd' => ['category', 'name', 'tag', 'value_type'],
        'getRow' => ['id'],
        'getCategoryList' => ['category'],
        'saveCategoryList' => ['config_list'],
    ];

    // edit 验证场景定义
    public function sceneSaveEdit()
    {
        return $this->only(['id', 'tag'])
              ->remove('tag', 'require');
    }

    public function sceneGetTagConfig()
    {
        return $this->only(['tag'])->remove('tag', 'unique');
    }
}
